# wx驱动测试构建文件

if build_tests
    # 创建测试专用的静态库，包含接口源文件，设置 -fvisibility=default 导出符号
    wx_interface_sources = files(
        '../../../../drivers/pcie_nic_card/wx/interface/network_adapter/cooling.cpp',
        '../../../../drivers/pcie_nic_card/wx/interface/network_port/link_info.cpp',
        '../../../../drivers/pcie_nic_card/wx/interface/network_port/lldp_receive.cpp',
        '../../../../drivers/pcie_nic_card/wx/interface/board.cpp',
        '../../../../drivers/pcie_nic_card/wx/interface/network_adapter.cpp',
        '../../../../drivers/pcie_nic_card/wx/interface/network_port.cpp',
        '../../../../drivers/pcie_nic_card/wx/interface/pcie_card.cpp',
        '../../../../drivers/pcie_nic_card/wx/interface/pcie_device.cpp',
    )
    
    wx_card_port_sources = files(
        '../../../../drivers/pcie_nic_card/wx/wx_card.cpp',
        '../../../../drivers/pcie_nic_card/wx/wx_port.cpp',
    )
    
    # 测试专用的静态库，覆盖 -fvisibility=hidden，使用 -fvisibility=default 导出符号
    # 注意：需要包含 wx 驱动的所有 include 路径，因为接口源文件使用相对路径引用头文件
    # 确保 wx 相关的路径在 hisi 路径之前，避免找到错误的头文件
    wx_test_static_lib = static_library(
        'wx_test',
        wx_interface_sources + wx_card_port_sources,
        include_directories: [
            include_directories('../../../../drivers/pcie_nic_card/wx'),
            include_directories('../../../../drivers/pcie_nic_card/wx/interface'),
            include_directories('../../../../libraries/ncsi_over_mctp'),
            include_directories('../../../../include'),
            include_directories('../../../../gen/include'),
            include_directories('../../../../drivers/chip'),
            include_directories('../../../../drivers/internal'),
            include_directories('../../../../drivers/bus/i2c'),
            include_directories('../../../../libraries'),
            include_directories('../../../../libraries/smbus'),
            include_dirs,  # 放在最后，避免 hisi 路径干扰
        ],
        dependencies: [
            dev_deps,
            libncsi_over_mctp_dep,
            libmctp_dep,
            libimu_dep,
        ],
        cpp_args: ['-fvisibility=default', '-DUNIT_TEST'],
        install: false,
    )

    test_wx_abi_sources = [
        '../../../main.cpp',
        'test_wx_abi.cpp',
        'test_wx_card.cpp',
        'test_wx_port.cpp',
        '../../../libraries/ncsi_over_mctp/mock_mctp.cpp',
    ] + chip_interface_sources + blockio_interface_sources

    test_wx_abi = executable(
        'test_wx_abi',
        test_wx_abi_sources,
        include_directories: [
            include_dirs,
            include_directories('../../../../drivers/pcie_nic_card/wx'),
            include_directories('../../../../libraries'),
            include_directories('../../../../drivers'),
            include_directories('../../../../drivers/bus/i2c'),
            include_directories('../../../../drivers/internal'),
            include_directories('../../../../drivers/chip'),
            include_directories('../../../../libraries/smbus'),
        ],
        dependencies: [
            gtest_dep,
            test_utilities_dep,
            test_utils_dep,
            dev_deps,
            libncsi_over_mctp_dep,
            libmctp_dep,
            libimu_dep,
            ipmb_dep,
        ],
        link_whole: [internal_static_lib, wx_test_static_lib],
        link_args: ['-ldl'],
        cpp_args: ['-DUNIT_TEST'],
        install: false,
    )

    test('test_wx_abi', test_wx_abi,
         workdir: meson.build_root(),
         timeout: 180)
endif